%% Run model on alternative data sets to generate results for Table 2

clear
clc

addpath('functions');
addpath('data');
 

%% Settings

% Data Location and Adjustments

settings.remove_means = 1;
settings.standardise = 0;                               % Standardise all Variables Prior to estimation (optional)
settings.remove_outliers = 1;                           % Remove outliers following Stock and Watson (reccommended)

% Model Specification


settings.WhereQuartYoY = [];
settings.soft6 = [];

settings.constant = 0;                                  % Add constant in VAR

settings.nf = 1;                                        % Number of latent factors

settings.p = 2;                                         % Maximum lag order of factor VAR
settings.s = 0;                                         % Maximum factor lags that load observables (0 = contemporaneous only)
settings.q = 2;                                         % Order of serial correlation in idiosyncratic components. Max = 5;

settings.vardiag = 0;

settings.trend = 1;

settings.SV_factors = 1;                                % Add Stochastic Volatility to the common factors (0 = no; 1 = yes);
settings.SV_idiosyncratic = 1;

                        
                              
% Gibss Sampler Setting

settings.nreps = 10000;      % Number of Gibbs Sampler Draws
settings.nburn = 4000;   % Discard the first nburn draws as Burn-in Draws

settings.show_plots = 0;
settings.plot_each = 1;

%% Bayesian Priors

settings.var_priors = 0;     % 0 = Noninformative; 1 = Independent N-IW;
settings.lambda_priors = 0;   % 0 = Noninformative; 1 = shrink towards zero
settings.rho_priors = 0;     % 0 = Noninformative; 1 = shrink towards zero

settings.prior_trend = 1*(1/settings.trend)*0.001;
settings.prior_SV = 0.0001;
settings.prior_SV_sm = 0.0001;


%% Load big data set

load('ADP_extended.mat')
yraw0=yraw;

%% Baseline ADP

settings.WhereQuarterly = [1:4];
settings.schemenumber = 51;

variable_select = [1:28];
yraw = yraw0(:,variable_select);

seed = RandStream('mt19937ar','Seed',1);
RandStream.setGlobalStream(seed);

[results] = DFM_function3_Simple(settings,yraw,dates,datenum(now));

v2struct(results);
save('output\results_Table2_base','trend_uncertainty','cycle_uncertainty',... 
'trend_uncertainty2','trend_percentiles');

%% Baseline ADP, No Consumption

settings.WhereQuarterly = [1:4];
settings.schemenumber = 5;

variable_select = [1:28];
yraw = yraw0(:,variable_select);

seed = RandStream('mt19937ar','Seed',1);
RandStream.setGlobalStream(seed);

[results] = DFM_function3_Simple(settings,yraw,dates,now);

v2struct(results);
save('output\results_Table2_basenoC','trend_uncertainty','cycle_uncertainty',... 
'trend_uncertainty2','trend_percentiles');


%% Okun

settings.WhereQuarterly = [1];
settings.schemenumber = 5;

variable_select = [1,17];
yraw = yraw0(:,variable_select);
yraw(:,2) = - yraw(:,2);

seed = RandStream('mt19937ar','Seed',1);
RandStream.setGlobalStream(seed);

[results] = DFM_function3_Simple(settings,yraw,dates,datenum(now));

v2struct(results);
save('output\results_Table2_okun','trend_uncertainty','cycle_uncertainty',... 
'trend_uncertainty2','trend_percentiles');

%% Mariano murasawa

settings.WhereQuarterly = [1];
settings.schemenumber = 5;

variable_select = [1,5,8,9,15];
yraw = yraw0(:,variable_select);

seed = RandStream('mt19937ar','Seed',1);
RandStream.setGlobalStream(seed);

[results] = DFM_function3_Simple(settings,yraw,dates,datenum(now));

v2struct(results);
save('output\results_Table2_mm','trend_uncertainty','cycle_uncertainty',... 
'trend_uncertainty2','trend_percentiles');


%% Extended ADP

settings.WhereQuarterly = [1:4];
settings.schemenumber = 51;
settings.standardise = 1;                               % Standardise all Variables Prior to estimation (optional)
settings.s = 5;                                         % Maximum factor lags that load observables (0 = contemporaneous only)
settings.var_priors = 3;     % 0 = Noninformative; 1 = Independent N-IW;
settings.lambda_priors = 2;   % 0 = Noninformative; 1 = shrink towards zero
settings.rho_priors = 2;     % 0 = Noninformative; 1 = shrink towards zero

variable_select = [1:155];
yraw = yraw0(:,variable_select);

seed = RandStream('mt19937ar','Seed',1);
RandStream.setGlobalStream(seed);

[results] = DFM_function3_Extended(settings,yraw,dates,datenum(now));

v2struct(results);
save('output\results_Table2_ext','trend_uncertainty','cycle_uncertainty',... 
'trend_uncertainty2','trend_percentiles');

%% Extended ADP, No Consumption

settings.WhereQuarterly = [1:4];
settings.schemenumber = 5;
settings.standardise = 1;                               % Standardise all Variables Prior to estimation (optional)
settings.s = 5;                                         % Maximum factor lags that load observables (0 = contemporaneous only)
settings.var_priors = 3;     % 0 = Noninformative; 1 = Independent N-IW;
settings.lambda_priors = 2;   % 0 = Noninformative; 1 = shrink towards zero
settings.rho_priors = 2;     % 0 = Noninformative; 1 = shrink towards zero

variable_select = [1:155];
yraw = yraw0(:,variable_select);

seed = RandStream('mt19937ar','Seed',1);
RandStream.setGlobalStream(seed);

[results] = DFM_function3_Extended(settings,yraw,dates,datenum(now));

v2struct(results);
save('output\results_Table2_extnoC','trend_uncertainty','cycle_uncertainty',... 
'trend_uncertainty2','trend_percentiles');